package com.anrongtec.zcpt.module;

import android.content.Context;

import com.anrongtec.zcpt.interfaces.ShuJuURL;
import com.anrongtec.zcpt.util.Util;
import com.google.gson.annotations.Expose;
import com.litesuits.orm.db.annotation.PrimaryKey;
import com.litesuits.orm.db.annotation.Table;
import com.litesuits.orm.db.enums.AssignType;

import java.io.Serializable;

/**
 * app更新升级信息
 * @author cxy
 *
 */
@Table("appUpgrade")
public class AppUpgrade implements Serializable{
	@Expose
	@PrimaryKey(AssignType.BY_MYSELF)
	private String pkg;
	
	@Expose
	private int versionCode;
	
	@Expose
	private boolean update;//是否需要升级 false：否，true1：是
	
	@Expose
	private int expVersionCode;//期望升级版本号
	
	@Expose
	private String expFileId;//期望升级的文件下载URL,下载apk时请把公共参数加上
	
	@Expose
	private long expSize;

	public String getPkg() {
		return pkg;
	}

	public void setPkg(String pkg) {
		this.pkg = pkg;
	}

	public int getVersionCode() {
		return versionCode;
	}

	public void setVersionCode(int versionCode) {
		this.versionCode = versionCode;
	}

	public boolean isUpdate() {
		return update;
	}

	public void setUpdate(boolean update) {
		this.update = update;
	}

	public int getExpVersionCode() {
		return expVersionCode;
	}

	public void setExpVersionCode(int expVersionCode) {
		this.expVersionCode = expVersionCode;
	}

	public String getExpFileId() {
		return expFileId;
	}

	public void setExpFileId(String expFileId) {
		this.expFileId = expFileId;
	}

	public long getExpSize() {
		return expSize;
	}

	public void setExpSize(long expSize) {
		this.expSize = expSize;
	}
	
	/**
	 * upgrade to appmodel
	 * @return
	 */
	public AppModel toAppModel(Context context){
		AppModel app = Util.getAppInfoByPkg(context, this.getPkg());
		app.setRemoteVersionCode(this.getExpVersionCode());//远程版本号
		app.setUrl(ShuJuURL.DownloadURL() + this.getExpFileId());//下载url   http://211.149.241.114.:8080/store/download?fileId=
		app.setSize(this.getExpSize());//远程大小
		return app;
	}
}
